*******************************************************************************************************************************************************************RESEARCH PROJECT: OFFSHORING AND IMMIGRATION****************************************************************************************************************************AUTHOR :**********************************************************************Dario P.********************************************************************************************************local stdate $S_DATElocal sttime $S_TIMEclearcapture log closeglobal prgrms "DO\"global logs "LOG\"global data "DARIO\DATA\"global tables "TABLE\"global graph "GRAPH\"set mem 5gset matsize 800set more offcd "G:\data\workdata\707562"*******FIGURES use ${data}offshoring_fin_will.dta, clear******add immigration variable  in levelssort akom yearmerge akom year using ${data}for_non_eu_count.dtakeep if _merge==3drop _mergesort akom yearmerge akom year using ${data}iv_off_count.dtakeep if _merge==3preserve keep cvrnr yearsort cvrnr yearsave ${data}final_sample.dta, replacerestorecollapse ext_narrow_off, by(year)rename ext_narrow_off offshoringreplace offshoring=offshoring*100label var offshoring "Percent of offshoring firms"twoway (line offshoring year) (scatter offshoring year), graphregion(color(white))  legend(off) ylabel(15(5)35) xlabel(1993(2)2011)  ///			 xline(2004,lpattern(dash)) xline(1994,lpattern(dash))graph save ${graph}figure_2b.gph, replacegraph export  ${graph}figure_2b.pdf, replace****************SECOND GRAPH AS IN PERI/FOGED****************SECOND GRAPH AS IN PERI/FOGEDuse "G:\Data\Workdata\703989\STATA FILES\idapall5.dta" if aar>="1993" & aar<="2011", clearkeep if pstill>="31" & pstill<="37"sort hfauddmerge hfaudd using ${data}udd.dtakeep if _merge==3drop _mergegen edu=substr(hffsp,1,2)destring edu, replacegen skill1=(edu==20 | edu==25 | edu==35| edu==40)gen skill2=(edu==50 | edu==60 | edu==65 | edu==70)gen skill3=(skill1==0 & skill2==0)gen years_of_edu=0replace years_of_edu=7 if edu==10replace years_of_edu=11 if edu==15 | edu==35replace years_of_edu=12 if edu==20 | edu==25 | edu==39replace years_of_edu=14 if edu==40 replace years_of_edu=15 if edu==50 | edu==60replace years_of_edu=18 if edu==65replace years_of_edu=22 if edu==70replace years_of_edu=6 if edu==.gen manager=pstill=="31"gen ml=pstill=="32" | pstill=="33" | pstill=="34"gen bc=(manager==0 & ml==0)gen work_exp=erhver/1000rename opr_land ielandgen birthy=year(foed_dag)rename aar yeardestring year, replacedestring birthy, replacegen age=year-birthybysort pnr year: gen id=_nkeep if id==1rename ie_type ietypegen natives=ietype=="1"gen foreigner=(natives!=1)gen foreigner_EU=(ieland=="5126" | ieland=="5130" | ieland=="5180" | ieland=="5134" | ieland=="5142" | ieland=="5150" | ieland=="5108" | ieland=="5140" | /**/ ieland=="5156" | ieland=="5164" | ieland=="5170"  | ieland=="5182" | ieland=="5104" | ieland=="5120")gen natives2=(ietype=="1") | ieland=="5126" | ieland=="5130" | ieland=="5180" | ieland=="5134" | ieland=="5142" | ieland=="5150" | ieland=="5108" | ieland=="5140" | /**/ ieland=="5156" | ieland=="5164" | ieland=="5170"  | ieland=="5182" | ieland=="5104" | ieland=="5120" gen foreigner_nonEU=(natives2!=1)gen foreigner_new_eu=(ieland=="5776" | ieland=="5607" | ieland=="5174" | ieland=="5609" | ieland=="5611" | ieland=="5154" /**/ | ieland=="5778" | ieland=="5752" | ieland=="5153" | ieland=="5422" | ieland=="5158" | ieland=="5128" )replace foreigner_nonEU=0 if foreigner_new_eu==1collapse  foreigner foreigner_EU foreigner_nonEU foreigner_new_eu, by(year) gen Total=foreignergen New_EU_member=foreigner_new_eugen EU=foreigner_EUgen Non_EU=foreigner-EU-New_EU_memberlabel var year "year"keep if year>=1993sort yeargraph twoway (line  Total year, lpattern(longdash_dot)  ) ///			 (line  EU year, lpattern(dot_dash)) ///			 (line  Non_EU year, lpattern(dash)) //           ,  ///             ytitle("") ///             xtitle("year") ///			 legend(size(small) /*pos(3) col(1)*/ col(4)) graphregion(color(white)) ylabel(0(0.01)0.07)			 ///xline(1994,lpattern(dash)) ///			/// xline(2004,lpattern(dash)) ///			 /// legend(ring(0) order(1 "quadratic fit" 2 "observed" 3 "quadratic fit" 4 "observed")) graph save ${graph}graph,replace save ${data}graph,replace restoregraph save ${graph}figure1.gph, replacegraph export  ${graph}figure1.pdf, replace*********************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER***************************************************************************************************************THIS IS CURRENT FIGURE 1 IN THE LAST VERSION OF OUR PAPER******************************************************************twoway (line Non_EU year) (scatter Non_EU year), graphregion(color(white))  legend(off)  xlabel(1993(2)2011) ylabel(1(1)5)  ytitle("Percent of non-EU immigrants")  /*			 */ xline(2004,lpattern(dash)) xline(1994,lpattern(dash))graph save ${graph}figure_1a.gph, replacerestoregraph combine  ${graph}figure_1a.gph ${graph}figure_2b.gph,  graphregion(color(white)) col(1)graph export  ${graph}figure5.pdf, replace*********************************************THIS IS CURRENT FIGURE 5 IN THE LAST VERSION OF OUR PAPER******************************************************************use ${data}import_ind_d.dta, clear***merge with the accountingsdestring cvrnr, replacesort cvrnr yearmerge cvrnr year using ${data}industry.dtadrop if _merge==1drop _mergekeep if year>=1995 & year<=2011sort cvrnr yearmerge cvrnr year using ${data}foreign_ownership.dtakeep if _merge==3drop _mergedestring GF_VIRKFKOD, replacegen foreign=GF_VIRKFKOD==160 | GF_VIRKFKOD==170 |  GF_VIRKFKOD==180 | GF_VIRKFKOD==190 | GF_VIRKFKOD==196 | GF_VIRKFKOD==200 | GF_VIRKFKOD==210 | GF_VIRKFKOD==220 | GF_VIRKFKOD==290 | GF_VIRKFKOD==291sort cvrnr yearsort cvrnr yearmerge cvrnr year using ${data}antalarb.dtakeep if _merge==3drop _mergegen  multi=antalarb>1***gen useful firm-level controls: productivity, size etc...gen deflator=0replace deflator=0.86 if year==1993replace deflator=0.87 if year==1994replace deflator=0.89 if year==1995replace deflator=0.91 if year==1996replace deflator=0.93 if year==1997replace deflator=0.95 if year==1998replace deflator=0.97 if year==1999replace deflator=1 if year==2000replace deflator=1.02 if year==2001replace deflator=1.05 if year==2002replace deflator=1.07 if year==2003replace deflator=1.08 if year==2004replace deflator=1.10 if year==2005replace deflator=1.12 if year==2006replace deflator=1.14 if year==2007replace deflator=1.18 if year==2008replace deflator=1.2 if year==2009replace deflator=1.22 if year==2010replace deflator=1.26 if year==2011replace deflator=1.29 if year==2012destring GF_BRANCHE_07, gen(bra07)format bra07 %06.0freplace bra07=-999 if bra07==.bysort GF_BRANCHE_03 cvrnr: egen bra07_max=max(bra07)replace bra07=bra07_max if bra07==-999replace bra07=. if bra07==-999gen branche=bra07tostring branche, gen(branche1)gen branche2=substr(branche1, 1,2)****calculate industry classification 1-digit 2007gen bra=.***manufacturingreplace bra=1 if branche2>="10" & branche2<="33"***electricity, waterreplace bra=2 if branche2=="35" & branche2<="39"***constructionreplace bra=3 if branche2>="41" & branche2<="43"***wholesale and retail tradereplace bra=4 if branche2>="45" & branche2<="47"***transportreplace bra=5 if branche2>="49" & branche2<="56"***information and comunicationreplace bra=6 if branche2>="58" & branche2<="63"***financial services & real estate & business servicereplace bra=7 if branche2>="64" & branche2<="75"***other servicesreplace bra=8 if branche2>="77" & branche2<="97"gen sales=GF_OMSdrop if sales<0drop if GF_EGUL<0replace sales=sales/deflatorreplace GF_EGUL=GF_EGUL/deflatorreplace  GF_E_GUL= GF_E_GUL/deflator****merge with firm size: with dataset has been created by globid from: G:\Data\Workdata\703989\STATA FILES\idfisort cvrnr yearmerge cvrnr year using ${data}firm_size2.dtakeep if _merge==3 drop _mergegen tot_emp=fanshgen size1=(tot_emp>=1 & tot_emp<20)gen size2=(tot_emp>=20 & tot_emp<50)gen size3=(tot_emp>=50)gen productivity=ln(sales/tot_emp)gen capital_int=.replace capital_int=ln(GF_EGUL/tot_emp) if year>=1999replace capital_int=ln(GF_E_GUL/tot_emp) if year<1999****merge with workforce characteristicts retrived from the matched employer-employee databasesort cvrnr yearmerge cvrnr year using ${data}demographic.dtakeep if _merge==3drop _merge***MERGE WITH MUNICIPALITY LEVEL SHARE OF NON-EU FOREIGNERSsort akom yearmerge akom year using ${data}for_non_eu.dtakeep if _merge==3drop _merge***MERGE WITH ITS INSTRUMENT sort akom yearmerge akom year using ${data}iv_off5.dtakeep if _merge==3drop _mergesum s_hat, detcorr s_hat foreigner_nonEU_mun***gen intensive and extensive margins of offshoringreplace broad_off=0 if broad_off==.replace narrow_off=0 if narrow_off==.gen ext_broad_off=(broad_off>0)gen ext_narrow_off=(narrow_off>0)gen int_broad_off=ln(broad_off)gen int_narrow_off=ln(narrow_off)global cntrl2 "male  age years_of_edu   tenure work_exp"****summary statsdrop if branche2=="."drop if year<1995drop if year==2012drop if tot_emp<2drop if productivity==.drop if capital_int==.drop if bra==2sort cvrnr yearmerge cvrnr year using ${data}desti_will.dtakeep if _merge==1 | _merge==3drop _mergereplace destinations=0 if destinations==.***SPECIFIC STATS ON OFFSHORINGgen man=bra==1bysort cvrnr year: gen id=_nkeep if id==1xtset cvrnr yeargen foreign_o=l.foreigndrop foreignrename foreign_o foreigngen prod=l.productivitygen cap=l.capital_intgen for=l.foreigner_nonEU_mungen for_iv=l.s_hatgen region=0replace region=1 if akom>=101 & akom<=250replace region=1 if akom==260 | akom==270 | akom==400replace region=2 if akom==253 | akom==259 | akom==265 | akom==269replace region=2 if akom>=306 & akom<=390replace region=3 if akom>=410 & akom<=580replace region=3 if akom==607  | akom==621 | akom==630replace region=4 if akom>=615 & akom<=766 replace region=4 if akom==779 | akom==791replace region=5 if akom==773 | akom==787replace region=5 if akom>=810 & akom<=860destring branche2, replace***drop those firms that move to another akom for the clusterbysort cvrnr: egen akom_m=max(akom)gen change=(akom!=akom_m)drop if change==1rename int_narrow_off offrename for for3reg off i.year i.akompredict off2, resreg for3 i.year i.akompredict for3_p, rescollapse  off2  for3_p, by(akom year)label var off2 "Intensive margin of offshoring"label var  for3   "Share of non-EU immigrants"twoway (scatter off2 for3) (lfitci off2 for3, alpattern(dash) fcolor(none)), graphregion(color(white))   legend(off) ytitle("Intensive margin of offshoring")graph save ${graph}figure8.gph, replacegraph export  ${graph}figure8.pdf, replace*********************************************THIS IS CURRENT FIGURE 8 IN THE LAST VERSION OF OUR PAPER******************************************************************use ${data}import_ind_d.dta, clear***merge with the accountingsdestring cvrnr, replacesort cvrnr yearmerge cvrnr year using ${data}industry.dtadrop if _merge==1drop _mergekeep if year>=1995 & year<=2011sort cvrnr yearmerge cvrnr year using ${data}foreign_ownership.dtakeep if _merge==3drop _mergedestring GF_VIRKFKOD, replacegen foreign=GF_VIRKFKOD==160 | GF_VIRKFKOD==170 |  GF_VIRKFKOD==180 | GF_VIRKFKOD==190 | GF_VIRKFKOD==196 | GF_VIRKFKOD==200 | GF_VIRKFKOD==210 | GF_VIRKFKOD==220 | GF_VIRKFKOD==290 | GF_VIRKFKOD==291sort cvrnr yearsort cvrnr yearmerge cvrnr year using ${data}antalarb.dtakeep if _merge==3drop _mergegen  multi=antalarb>1***gen useful firm-level controls: productivity, size etc...gen deflator=0replace deflator=0.86 if year==1993replace deflator=0.87 if year==1994replace deflator=0.89 if year==1995replace deflator=0.91 if year==1996replace deflator=0.93 if year==1997replace deflator=0.95 if year==1998replace deflator=0.97 if year==1999replace deflator=1 if year==2000replace deflator=1.02 if year==2001replace deflator=1.05 if year==2002replace deflator=1.07 if year==2003replace deflator=1.08 if year==2004replace deflator=1.10 if year==2005replace deflator=1.12 if year==2006replace deflator=1.14 if year==2007replace deflator=1.18 if year==2008replace deflator=1.2 if year==2009replace deflator=1.22 if year==2010replace deflator=1.26 if year==2011replace deflator=1.29 if year==2012destring GF_BRANCHE_07, gen(bra07)format bra07 %06.0freplace bra07=-999 if bra07==.bysort GF_BRANCHE_03 cvrnr: egen bra07_max=max(bra07)replace bra07=bra07_max if bra07==-999replace bra07=. if bra07==-999gen branche=bra07tostring branche, gen(branche1)gen branche2=substr(branche1, 1,2)****calculate industry classification 1-digit 2007gen bra=.***manufacturingreplace bra=1 if branche2>="10" & branche2<="33"***electricity, waterreplace bra=2 if branche2=="35" & branche2<="39"***constructionreplace bra=3 if branche2>="41" & branche2<="43"***wholesale and retail tradereplace bra=4 if branche2>="45" & branche2<="47"***transportreplace bra=5 if branche2>="49" & branche2<="56"***information and comunicationreplace bra=6 if branche2>="58" & branche2<="63"***financial services & real estate & business servicereplace bra=7 if branche2>="64" & branche2<="75"***other servicesreplace bra=8 if branche2>="77" & branche2<="97"gen sales=GF_OMSdrop if sales<0drop if GF_EGUL<0replace sales=sales/deflatorreplace GF_EGUL=GF_EGUL/deflatorreplace  GF_E_GUL= GF_E_GUL/deflator****merge with firm size: with dataset has been created by globid from: G:\Data\Workdata\703989\STATA FILES\idfisort cvrnr yearmerge cvrnr year using ${data}firm_size2.dtakeep if _merge==3 drop _mergegen tot_emp=fanshgen size1=(tot_emp>=1 & tot_emp<20)gen size2=(tot_emp>=20 & tot_emp<50)gen size3=(tot_emp>=50)gen productivity=ln(sales/tot_emp)gen capital_int=.replace capital_int=ln(GF_EGUL/tot_emp) if year>=1999replace capital_int=ln(GF_E_GUL/tot_emp) if year<1999****merge with workforce characteristicts retrived from the matched employer-employee databasesort cvrnr yearmerge cvrnr year using ${data}demographic.dtakeep if _merge==3drop _merge***MERGE WITH MUNICIPALITY LEVEL SHARE OF NON-EU FOREIGNERSsort akom yearmerge akom year using ${data}for_non_eu.dtakeep if _merge==3drop _merge***MERGE WITH ITS INSTRUMENT sort akom yearmerge akom year using ${data}iv_off5.dtakeep if _merge==3drop _mergesum s_hat, detcorr s_hat foreigner_nonEU_mun***gen intensive and extensive margins of offshoringreplace broad_off=0 if broad_off==.replace narrow_off=0 if narrow_off==.gen ext_broad_off=(broad_off>0)gen ext_narrow_off=(narrow_off>0)gen int_broad_off=ln(broad_off)gen int_narrow_off=ln(narrow_off)global cntrl2 "male  age years_of_edu   tenure work_exp"****summary statsdrop if branche2=="."drop if year<1995drop if year==2012drop if tot_emp<2drop if productivity==.drop if capital_int==.drop if bra==2sort cvrnr yearmerge cvrnr year using ${data}desti_will.dtakeep if _merge==1 | _merge==3drop _mergereplace destinations=0 if destinations==.***SPECIFIC STATS ON OFFSHORINGgen man=bra==1bysort cvrnr year: gen id=_nkeep if id==1xtset cvrnr yeargen foreign_o=l.foreigndrop foreignrename foreign_o foreigngen prod=l.productivitygen cap=l.capital_intgen for=l.foreigner_nonEU_mungen for_iv=l.s_hatgen region=0replace region=1 if akom>=101 & akom<=250replace region=1 if akom==260 | akom==270 | akom==400replace region=2 if akom==253 | akom==259 | akom==265 | akom==269replace region=2 if akom>=306 & akom<=390replace region=3 if akom>=410 & akom<=580replace region=3 if akom==607  | akom==621 | akom==630replace region=4 if akom>=615 & akom<=766 replace region=4 if akom==779 | akom==791replace region=5 if akom==773 | akom==787replace region=5 if akom>=810 & akom<=860gen akomc=akom*yeardestring branche2, replace***drop those firms that move to another akom for the clusterbysort cvrnr: egen akom_m=max(akom)gen change=(akom!=akom_m)drop if change==1rename ext_narrow_off offrename for for3reg off i.year i.akompredict off_p, resreg for3 i.year i.akompredict for3_p, rescollapse  off_p  for3_p, by(akom year)label var off "Share of offshoring firms"label var  for3   "Share of non-EU immigrants"twoway (scatter off for3) (lfitci off for3 , alpattern(dash) fcolor(none)), graphregion(color(white))   legend(off) ytitle("Extensive margin of offshoring")graph save ${graph}figure7.gph, replacegraph export  ${graph}figure7.pdf, replace*********************************************THIS IS CURRENT FIGURE 7 IN THE LAST VERSION OF OUR PAPER**********************************************************************VALIDITY INSTRUMENTSuse ${data}offshoring_fin_will.dta, clearsort s_hatreplace s_hat=s_hat*100replace foreigner_nonEU_mun=foreigner_nonEU_mun*100label var s_hat "Predicted share of non-EU immigrants"label var  foreigner_nonEU_mun   "Share of non-EU immigrants"twoway (scatter  foreigner_nonEU_mun s_hat) (lfitci  foreigner_nonEU_mun s_hat, alpattern(dash) fcolor(none)) , graphregion(color(white)) legend(off) ytitle("Share of non-EU immigrants")graph save ${graph}figure9.gph, replacegraph export  ${graph}figure9.pdf, replace*********************************************THIS IS CURRENT FIGURE 9 IN THE LAST VERSION OF OUR PAPER******************************************************************use ${data}offshoring_fin_will.dta, clear***as BERNARD, SMEETS, W AND FORTH (FIGURE1)bysort branche2 year: egen total_off_ind=total(ext_narrow_off)bysort branche2 year: gen total_firms=_Negen total_off=total(ext_narrow_off)gen share_off_ind=total_off_ind/total_firmsgen share_off=total_off_ind/total_offcollapse share_off_ind, by(branche2)gsort  -  share_off_indkeep in 1/12label var share_off_ind "share of offshoring firms within industry"graph bar  share_off_ind, over(branche2, label(labsize(small)) sort(1) descending)  graphregion(color(white)) ytitle("Share of offshoring firms within industry")   graph save ${graph}figure4.gph, replacegraph export  ${graph}figure4.pdf, replacerestore********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATION********FIGURES ON COUNTRIES OF ORIGIN AND COUNTRIES OF DESTINATIONuse ${data}iv_off_dis.dta, clearrename share_for2 for2collapse for2, by(year land)drop if land=="."encode land, gen(land2)tsset land2 yeargen for2_95=for2 if year==1995replace for2_95=-9999 if for2_95==. bysort land: egen for2_95_m=max(for2_95)replace for2_95_m=0 if for2_95_m<0gen change2=for2-for2_95_mgen change2b=((change2)/(for2_95_m))*100gen change2b_rs=change2b if land=="RS"replace change2b_rs=-9999 if change2b_rs==.bysort year: egen change2b_rs_m=max(change2b_rs)gen change2b_iq=change2b if land=="IQ"replace change2b_iq=-9999 if change2b_iq==.bysort year: egen change2b_iq_m=max(change2b_iq)gen change2b_so=change2b if land=="SO"replace change2b_so=-9999 if change2b_so==.bysort year: egen change2b_so_m=max(change2b_so)gen change2b_af=change2b if land=="AF"replace change2b_af=-9999 if change2b_af==.bysort year: egen change2b_af_m=max(change2b_af)gen change2b_ir=change2b if land=="IR"replace change2b_ir=-9999 if change2b_ir==.bysort year: egen change2b_ir_m=max(change2b_ir)gen change2b_pl=change2b if land=="PL"replace change2b_pl=-9999 if change2b_pl==.bysort year: egen change2b_pl_m=max(change2b_pl)gen change2b_ro=change2b if land=="RO"replace change2b_ro=-9999 if change2b_ro==.bysort year: egen change2b_ro_m=max(change2b_ro)gen change2b_bg=change2b if land=="BG"replace change2b_bg=-9999 if change2b_bg==.bysort year: egen change2b_bg_m=max(change2b_bg)keep if year>=1995graph twoway    (line  change2b_af_m year,lpattern(longdash_dot)) ///(line  change2b_ir_m year, lpattern(longdash)) ///(line  change2b_iq_m year, lpattern(dot)) ///			 (line  change2b_so_m year, lpattern(dash)) ///              (line  change2b_rs_m year, lpattern(dash_dot))  ///	(line  change2b_bg_m year, lpattern(shortdash) ) ///			  		  (line  change2b_pl_m year, lpattern(shortdash_dot)) ///					    (line  change2b_ro_m year) ///						 ,  ///             ytitle("") ///             xtitle("year") graphregion(color(white)) ///			 legend(size(small) /*pos(3) col(1)*/ col(4) /*symysize(3) symxsize(3)*/ order(1 "Afghanistan" 2 "Iran" 3 "Iraq" 4 "Somalia" 5 "Former Yugo" 6 "Bulgaria" 7 "Poland" 8 "Romania")) graph save ${graph}figure2.gph, replacegraph export  ${graph}figure2.pdf, replacekeep if year==2011gsort- change2bgraph bar change2b, over(land, label(labsize(tiny)) sort(1) descending) graphregion(color(white)) ytitle(Immigrant Percent Change)graph save ${graph}offshoring_destinations_a.gph, replace***open import_ind_c which is constructed by running the SAS pgrm "Trade_data"use ${data}import_ind_c.dta, replace****keep if year>=1995 as we don't have firm-level accounting before keep if year>=1995 replace vrd_imp=0 if vrd_imp==.rename HS4_imp HS6_imprename HS4_exp HS6_exprename HS4_dom_1 HS6_dom_1***construct a dummy for narrow offshoring (domestic sales or exports in the same 6 digit product as in imports)gen narrow= (HS6_imp==HS6_exp) replace narrow=1 if  (HS6_imp==HS6_dom_1) ***gen broad offshoring (disaggregated over all destinations)***gen broad offshoring (disaggregated over all destinations)	replace land="FR" if land=="MC"	replace land="FR" if land=="GF"replace land="FR" if land=="YT"replace land="FR" if land=="MQ"replace land="FR" if land=="RE"replace land="FR" if land=="GP"replace land="BE" if land=="LU"replace land="RS" if land=="ME"replace land="RS" if land=="HR"replace land="RS" if land=="SI"replace land="RS" if land=="MK"replace land="RS" if land=="CS"replace land="RS" if land=="XS"replace land="RS" if land=="XK"replace land="RS" if land=="BA"replace land="RS" if land=="YU"replace land="ZR" if land=="CD"replace land="ES" if land=="AD"replace land="ES" if land=="GI"replace land="ES" if land=="EA"replace land="ES" if land=="IC"replace land="ES" if land=="XC"replace land="ES" if land=="XL"replace land="GB" if land=="UK"replace land="US" if land=="UM"replace land="US" if land=="PR"replace land="US" if land=="VI"replace land="US" if land=="AS"replace land="IT" if land=="VA"replace land="IT" if land=="SM"replace land="MA" if land=="EH"replace land="CH" if land=="LI"replace land="NO" if land=="SJ"replace land="AR" if land=="FK"replace land="TP" if land=="TL"****drop unknown destinations, uncertain destinations***unknown destinationsdrop if land=="QU" | land=="QV" | land=="QW" | land=="QX"***antarticdrop if land=="AQ"***polar areadrop if land=="XR"***bonventøen (polar area)drop if land=="BV"***sandwich islands (polar area)drop if land=="GS"***british india ocean territorydrop if land=="IO"***french occupied as polar areadrop if land=="TF"***american oceanian territory drop if land=="XA"***australian oceanian territorydrop if land=="XO"****recode some to make compatible with the officals iso from country_codes dataset***GAZAreplace land="IL" if land=="XP"***recode canarian islands as spainreplace land="ES" if land=="XB"***recode guam as USAreplace land="US" if land=="GU"***heard island AS AUSTRALIAreplace land="AU" if land=="HM"*** NEW ZEALAND islands replace land="NZ" if land=="XZ"gen north=(land=="AT" | land=="BE"  | land=="FI" | land=="FR" | land=="DE" | land=="GR" | land=="IS" | land=="IE" | land=="IT" | land=="LI" | land=="NL" | land=="NO" | land=="PT" | /* */ land=="ES" | land=="SE" | land=="GB" | land=="CH" )drop if north==1destring cvrnr, replacesort cvrnr land yearmerge cvrnr land year using ${data}will_bil.dta, keep(cvrnr land year)drop if _merge==1replace narrow=0 if narrow==.bysort cvrnr land year: egen narrow_off=max(narrow)collapse ext_narrow_off=narrow_off, by(land year) cwgen ext_narrow_off_95=ext_narrow_off if year==1995replace ext_narrow_off_95=-99999 if ext_narrow_off_95==.bysort land: egen ext_narrow_off_95_m=max(ext_narrow_off_95)gen ext_narrow_off_11=ext_narrow_off if year==2011replace ext_narrow_off_11=-99999 if ext_narrow_off_11==.bysort land: egen ext_narrow_off_11_m=max(ext_narrow_off_11)gen change1b=((ext_narrow_off_11_m-ext_narrow_off_95_m)/(ext_narrow_off_95_m))*100preservecollapse  change1b, by(land) cwgsort -  change1bgraph bar change1b, over(land, label(labsize(tiny)) sort(1) descending) graphregion(color(white)) ytitle(Average Extensive Margin Percent Change)graph save ${graph}offshoring_destinations_b.gph, replacerestoregraph combine  ${graph}offshoring_destinations_a.gph ${graph}offshoring_destinations_b.gph,  graphregion(color(white)) col(1)graph save  ${graph}figure10.gph, replacegraph export  ${graph}figure10.pdf, replace